# Added to subversion
# Needed for connections
require 'Win32API'
require 'socket'
include Socket::Constants
require "ClassDebug.rb"
require "ClassSensor.rb"
require "ClassTank.rb"
require "ClassChatServer.rb"
require "ClassMotor.rb"
require "ClassK8055.rb"
require "ClassOutput.rb"




#openDevice.Call(0)
vm1 = K8055.new(0)

#vm1.outputAnalogChannel(1, 10)
#vm1.outputAnalogChannel(2, 90)

#vm1.testOutputs
leftDirOutput     = OutputVm.new("DO",vm1,2)
rightDirOutput    = OutputVm.new("DO",vm1,3)
leftSpeedOutput   = OutputVm.new("AO",vm1,1)
rightSpeedOutput  = OutputVm.new("AO",vm1,2)

lightsOutput = OutputVm.new("DO",vm1,5)
lightsOutput = 0

#leftDirOutput.set(0)
#rightDirOutput.set(1)
#leftSpeedOutput.set(0)
#rightSpeedOutput.set(100)
puts "output type: #{rightSpeedOutput.type}"


#OpenDevice (0)  


# Create some sensors
		incSensor = Sensor.new("inc")
		tiltSensor = Sensor.new("tilt",0,100,0,100,"deg",0.1,10)
		tiltSensor.simulate=true
		simSensor = Sensor.new("sim",0,100,0,100,"%",0.1,10)
		simSensor.simulate=true

		# create motors
		leftMainMotor = Motor.new("M1")
		rightMainMotor = Motor.new("M2")
		rightMainMotor.inverted=true
		

		# add outputs to motors
                leftMainMotor.attachOutput(leftDirOutput)
                leftMainMotor.attachOutput(leftSpeedOutput)

                rightMainMotor.attachOutput(rightDirOutput)
                rightMainMotor.attachOutput(rightSpeedOutput)

		# add sensors to motors
		
		
		
bigTank = Tank.new("Mytank",2200)
bigTank.addSensors(simSensor)
bigTank.addSensors(tiltSensor)

bigTank.addMotor(leftMainMotor,"left")
bigTank.addMotor(rightMainMotor,"right")




# add motors to tank

#bigTank.startServer
#bigTank.serverCommands

#server = ChatServer.new(2300)
#server.run
#puts "Conenctions: "
#puts server.clientcount.to_s

# loop
while !bigTank.breakLoop
	#puts "looping"
	
	sleep 1
end



